﻿

using Newtonsoft.Json;
using NurseStation.DataModels;
using System.IO;
using System.Windows;


namespace NurseStation.common
{

    public static class StringResourceHelper
    {
        private static XamlSetting SingleXamlSetting;

        /// <summary>
        /// 获取字符串资源
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static T GetString<T>(string key)
        {
            if (Application.Current.Resources.Contains(key))
            {
                if (Application.Current.Resources[key] is T temp)
                {
                    return temp;
                }
            }
            return default(T);
        }


        /// <summary>
        /// 获取xaml中配置
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static XamlSetting GetXamlSetting()
        {
            if (SingleXamlSetting == null)
            {
                try
                {
                    XamlSetting set0 = GetString<XamlSetting>("Setting");
                    if (set0 != null)
                    {
                        SingleXamlSetting =set0 ;
                    }
                    else 
                    {
                        SingleXamlSetting = new XamlSetting();
                    }

                }
                catch (Exception)
                {
                }
            }
            return SingleXamlSetting;
        }
    }
}
